#include <iostream>
#include "httplib.h"

void Hello(const httplib::Request& req, httplib::Response& rsp)
{
    rsp.set_content("hello world!", "text/plain");
    rsp.status = 200;
}
void Number(const httplib::Request& req, httplib::Response& rsp)
{
    auto num = req.matches[1]; //0里面保存的是整体的path，0之后保存的是捕捉的数据
    rsp.set_content(num, "text/plain");
    rsp.status = 200;
}

void Multipart(const httplib::Request& req, httplib::Response& rsp)
{
     auto ret = req.has_file("file"); //判断是否有文件上传
     if(ret == false)
     {
        std::cout<<"not file download"<<std::endl;
        rsp.status = 400;
        return;
     }
     const auto& file = req.get_file_value("file"); //有文件上传，获取文件数据
     rsp.body.clear();
     rsp.body = file.name; //获取文件名称
     rsp.body += '\n';
     rsp.body += file.content; //获取文件内容
     rsp.set_header("Content-Type","text/plain");
     rsp.status = 200;
} 

int main()
{
    httplib::Server server;   // 创建服务器对象搭建服务器
    server.Get("/hi", Hello); // 注册一个针对/hi的Get请求的处理函数的映射关系
    server.Get(R"(/number/(\d+))", Number);
    // server.Post("/multipart",Multipart);

        server.listen("0.0.0.0", 8080);
    return 0;
}